

package com.pc.admin.util;

import com.pc.admin.eunms.CodeEnum;
import com.pc.admin.exception.VerifyException;
import io.swagger.annotations.ApiModel;
import io.swagger.annotations.ApiModelProperty;
import org.apache.poi.ss.formula.functions.T;

import java.io.Serializable;

@ApiModel("json公共返回结果实体")
public class CommonResult<E> implements Serializable {
    private static final long serialVersionUID = 23456765435678L;
    @ApiModelProperty("响应业务状态")
    private Integer status;
    @ApiModelProperty("响应消息")
    private String msg;
    @ApiModelProperty("响应中的数据")
    private E data;
    @ApiModelProperty("skywalking追踪ID")
    private String traceId;

    public static <E> CommonResult<E> build(Integer status, String msg, E data) {
        return new CommonResult(status, msg, data);
    }

    public static <E> CommonResult<E> ok(E data) {
        return build(CodeEnum.SUCCESS.getCode(), CodeEnum.SUCCESS.getMsg(), data);
    }

    public static <E> CommonResult<E> ok() {
        return (CommonResult<E>) build(CodeEnum.SUCCESS.getCode(), CodeEnum.SUCCESS.getMsg(), (Object)null);
    }

    public static <E> CommonResult<E> ok(E object, String msg) {
        CommonResult<E> r = new CommonResult<E>();
        r.data = object;
        r.status = 1;
        r.msg = msg;
        return r;
    }


    public static <E> CommonResult<E> fail() {
        return build(CodeEnum.FAIL.getCode(), CodeEnum.FAIL.getMsg());
    }

    public static <E> CommonResult<E> fail(String msg) {
        return build(CodeEnum.FAIL.getCode(), msg);
    }

    public static <E> CommonResult<E> fail(Integer status, String msg) {
        return build(status, msg);
    }

    public static <E> CommonResult<E> sysError(String msg) {
        return build(CodeEnum.SYSTEM_ERROR.getCode(), msg);
    }

    public static <E> CommonResult<E> sysError(E data) {
        return build(CodeEnum.SYSTEM_ERROR.getCode(), CodeEnum.SYSTEM_ERROR.getMsg(), data);
    }

    public static void throwVerifyException(String msg) {
        throw new VerifyException(msg);
    }

    public CommonResult() {
    }

    public String getTraceId() {
        return this.traceId;
    }

    public void setTraceId(String traceId) {
        this.traceId = traceId;
    }

    public CommonResult(Integer status, String msg, E data) {
        this.status = status;
        this.msg = msg;
        this.data = data;
    }

    public static <E> CommonResult<E> build(Integer status, String message) {
        return new CommonResult(status, message, (Object)null);
    }

    public Integer getStatus() {
        return this.status;
    }

    public void setStatus(Integer status) {
        this.status = status;
    }

    public String getMsg() {
        return this.msg;
    }

    public void setMsg(String msg) {
        this.msg = msg;
    }

    public E getData() {
        return this.data;
    }

    public void setData(E data) {
        this.data = data;
    }

    public boolean isSuccess() {
        return CodeEnum.SUCCESS.getCode().equals(this.status);
    }

}